package com.guodexian.xiaomi.controller;

import com.guodexian.xiaomi.entity.Category;
import com.guodexian.xiaomi.service.CategoryService;
import com.guodexian.xiaomi.service.impl.CategoryServiceImpl;

import com.guodexian.xiaomi.util.HttpResponseUtil;
import com.guodexian.xiaomi.util.MyBeanUtils;
import com.guodexian.xiaomi.vo.ResultVO;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static org.apache.commons.beanutils.BeanUtils.populate;

@WebServlet("/category/edit")
public class CategoryEditController extends HttpServlet {
    private CategoryService categoryService = new CategoryServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1 获取参数
        Category category = new Category();
//        try {
//            BeanUtils.populate(category, req.getParameterMap());
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }

//        MyBeanUtils.populate(category, req.getParameterMap());
//
//        //2 调用业务层
//        ResultVO resultVO=categoryService.updateCategory(category);
//        //3 json
//        HttpResponseUtil.response(resp, resultVO);
    }
}